package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ModuleEngInfoPreview;
import com.ruoyi.system.service.IModuleEngInfoPreviewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工程导入预览Controller
 *
 * @author ruoyi
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/system/engPreview")
public class ModuleEngInfoPreviewController extends BaseController {
    @Autowired
    private IModuleEngInfoPreviewService moduleEngInfoPreviewService;

    /**
     * 查询工程导入预览列表
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModuleEngInfoPreview moduleEngInfoPreview) {
        startPage();
        List<ModuleEngInfoPreview> list = moduleEngInfoPreviewService
                .selectModuleEngInfoPreviewList(moduleEngInfoPreview);
        return getDataTable(list);
    }

    /**
     * 导出工程导入预览列表
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:export')")
    @Log(title = "工程导入预览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModuleEngInfoPreview moduleEngInfoPreview) {
        List<ModuleEngInfoPreview> list = moduleEngInfoPreviewService
                .selectModuleEngInfoPreviewList(moduleEngInfoPreview);
        ExcelUtil<ModuleEngInfoPreview> util = new ExcelUtil<ModuleEngInfoPreview>(ModuleEngInfoPreview.class);
        util.exportExcel(response, list, "工程导入预览数据");
    }

    /**
     * 获取工程导入预览详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(moduleEngInfoPreviewService.selectModuleEngInfoPreviewById(id));
    }

    /**
     * 新增工程导入预览
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:add')")
    @Log(title = "工程导入预览", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ModuleEngInfoPreview moduleEngInfoPreview) {
        return toAjax(moduleEngInfoPreviewService.insertModuleEngInfoPreview(moduleEngInfoPreview));
    }

    /**
     * 审核通过
     */
    @PostMapping("/approvedEng")
    public AjaxResult approvedEng(@RequestBody ModuleEngInfoPreview moduleEngInfoPreview) {
        return toAjax(moduleEngInfoPreviewService.approvedEng(moduleEngInfoPreview));
    }

    /**
     * 审核通过
     */
    @PostMapping("/noPassEng")
    public AjaxResult noPassEng(@RequestBody ModuleEngInfoPreview moduleEngInfoPreview) {
        return toAjax(moduleEngInfoPreviewService.noPassEng(moduleEngInfoPreview));
    }

    /**
     * 修改工程导入预览
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:edit')")
    @Log(title = "工程导入预览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModuleEngInfoPreview moduleEngInfoPreview) {
        return toAjax(moduleEngInfoPreviewService.updateModuleEngInfoPreview(moduleEngInfoPreview));
    }

    /**
     * 删除工程导入预览
     */
    // @PreAuthorize("@ss.hasPermi('system:preview:remove')")
    @Log(title = "工程导入预览", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(moduleEngInfoPreviewService.deleteModuleEngInfoPreviewByIds(ids));
    }
}
